package com.sunday.common.mq.kafka.study.spring.e6_Receiving_Messages_5_Json_Serializer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.KafkaListenerConfigurer;
import org.springframework.kafka.config.KafkaListenerEndpointRegistrar;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

/**
 * https://docs.spring.io/spring-kafka/docs/current/reference/html/#kafka-validation
 *
 * @KafkaListener @Payload验证
 * 从版本 2.2 开始，现在可以更轻松地添加 a 来验证参数。 以前，您必须配置自定义并将其添加到注册器。
 * 现在，您可以将验证器添加到注册商本身。 以下代码演示如何执行此操作：Validator@KafkaListener@PayloadDefaultMessageHandlerMethodFactory
 */
@Configuration
public class Config implements KafkaListenerConfigurer {

    @Autowired
    private LocalValidatorFactoryBean validator;

    @Override
    public void configureKafkaListeners(KafkaListenerEndpointRegistrar registrar) {
        registrar.setValidator(this.validator);
    }

}
